package com.wf.LeetCode;

/**
 * @author mpk
 * @since 2024/6/12 20:19:06
 */
public class CapitalizeTitle {
    public static void main(String[] args) {

        String title = "capiTalIze tHe titLe";
        System.out.println(capitalizeTitle(title));

    }
    public static String capitalizeTitle(String title) {

        String[] strings = title.split(" ");

        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < strings.length; i++) {

            if(strings[i].length()<=2)
            {
                strings[i]=strings[i].toLowerCase();
            }
            else
            {

                String s1 = strings[i].substring(0, 1).toUpperCase();
                String s2 = strings[i].substring(1).toLowerCase();
                strings[i] = s1 + s2;
            }

            stringBuilder.append(strings[i]).append(" ");
        }
        stringBuilder.deleteCharAt(title.length());




        return stringBuilder.toString();
    }




}
